#include <stdio.h>
#include <stdlib.h>
#include "MyVector.h"
#include <string.h>

#define RATIO 2 //动态数组扩展系数
#define SHOW_CAPACITY_SIZE_AND_LIST  \
        printf("容量->%d\t大小->%d\t\n", array->capacity, array->size); \
        DMArray_Travel(array, printfStudent);

typedef struct Student // 以动态数组存储的数据类型为Student*为例分析 
{
    char name[10];
    int age;
} Student;
int compare(void *s1, void *s2) //根据结构体Student设计比较规则，返回1表示相等
{
    Student *stu1 = (Student *)s1;//指针类型转换
    Student *stu2 = (Student *)s2;
    if (strcmp(stu1->name, stu2->name) == 0 && stu1->age == stu2->age)
        return 1;
    return 0;
}

void printfStudent(void *data) //为Student*类型数据写遍历函数
{
    Student *s = (Student *)data;
    printf("%s->%d\t", s->name, s->age);
}

int main()
{

    DMArray* array = DMArray_Init_pointer();

    Student s1 = {"jakes1", 16};
    Student s2 = {"jakes2", 17};
    Student s3 = {"jakes3", 18};
    Student s4 = {"jakes4", 19};
    Student s5 = {"jakes5", 20};
    Student s6 = {"jakes6", 21};
    DMArray_InsertByIndex(array, 0, &s1);
    SHOW_CAPACITY_SIZE_AND_LIST
    DMArray_InsertByIndex(array, 0, &s2);
    SHOW_CAPACITY_SIZE_AND_LIST
    DMArray_InsertByIndex(array, 1, &s3);
    SHOW_CAPACITY_SIZE_AND_LIST
    DMArray_InsertByIndex(array, 0, &s4);
    SHOW_CAPACITY_SIZE_AND_LIST
    DMArray_InsertByIndex(array, 1, &s5);
    SHOW_CAPACITY_SIZE_AND_LIST
    DMArray_InsertByIndex(array, 2, &s6);
    SHOW_CAPACITY_SIZE_AND_LIST
    DMArray_RemoveByIndex(array, 2);
    SHOW_CAPACITY_SIZE_AND_LIST
    
    SHOW_CAPACITY_SIZE_AND_LIST

    return 0;
}